<!--
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements.  See the NOTICE file distributed with
this work for additional information regarding copyright ownership.
The ASF licenses this file to You under the Apache License, Version 2.0
(the "License"); you may not use this file except in compliance with
the License.  You may obtain a copy of the License at
  http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<!DOCTYPE html>
<html lang=en>
    <head>
        <meta charset=utf-8>
        <meta http-equiv="X-UA-Compatible" content="IE=edge">
        <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
        <meta name="robots" content="index, follow">
        <link href="img/favicon.png" rel="shortcut icon" />
        <title>Graph Query Language - Gremlin | Apache TinkerPop</title>
        <meta name="description" content="Gremlin is a graph traversal language for querying databases with a functional, data-flow approach. Learn how to use this powerful query language.">
        <meta name="keywords" content="graph query, Gremlin, traversal, TinkerPop">
        <link rel="canonical" href="https://tinkerpop.apache.org/gremlin.html">
        
        <!-- Open Graph / Facebook -->
        <meta property="og:type" content="website">
        <meta property="og:url" content="https://tinkerpop.apache.org/gremlin.html">
        <meta property="og:title" content="Graph Query Language - Gremlin | Apache TinkerPop">
        <meta property="og:description" content="Gremlin is a graph traversal language for querying databases with a functional, data-flow approach. Learn how to use this powerful query language.">
        <meta property="og:image" content="https://tinkerpop.apache.org/img/gremlin/gremlin-logo.png">
        
        <!-- Twitter -->
        <meta name="twitter:card" content="summary_large_image">
        <meta name="twitter:site" content="@apachetinkerpop">
        <meta name="twitter:title" content="Graph Query Language - Gremlin | Apache TinkerPop">
        <meta name="twitter:description" content="Gremlin is a graph traversal language for querying databases with a functional, data-flow approach. Learn how to use this powerful query language.">
        <meta name="twitter:image" content="https://tinkerpop.apache.org/img/gremlin/gremlin-logo.png">
        
        <link href="css/bootstrap.min.css" rel="stylesheet">
        <link href="css/font-awesome.css" rel="stylesheet"/>
        <link href="css/custome.css" rel="stylesheet">
        <link href="css/responsive.css" rel="stylesheet">
        <link href="css/animate.css" rel="stylesheet"/>
        <link href="css/prism.css" rel="stylesheet">
        <link href="css/fonts.css" rel="stylesheet">

        <!-- Matomo -->
        <script>
            var _paq = window._paq = window._paq || [];
            /* We explicitly disable cookie tracking to avoid privacy issues */
            _paq.push(['disableCookies']);
            /* tracker methods like "setCustomDimension" should be called before "trackPageView" */
            _paq.push(['trackPageView']);
            _paq.push(['enableLinkTracking']);
            (function() {
                var u="https://analytics.apache.org/";
                _paq.push(['setTrackerUrl', u+'matomo.php']);
                _paq.push(['setSiteId', '27']);
                var d=document, g=d.createElement('script'), s=d.getElementsByTagName('script')[0];
                g.async=true; g.src=u+'matomo.js'; s.parentNode.insertBefore(g,s);
            })();
        </script>
        <!-- End Matomo Code -->
        
        <!-- Structured Data / JSON-LD -->
        <script type="application/ld+json">
        {
          "@context": "https://schema.org",
          "@graph": [
            {
              "@type": "Organization",
              "@id": "https://tinkerpop.apache.org/#organization",
              "name": "Apache TinkerPop",
              "url": "https://tinkerpop.apache.org/",
              "logo": {
                "@type": "ImageObject",
                "url": "https://tinkerpop.apache.org/img/logo.png",
                "width": 280,
                "height": 60
              },
              "description": "Apache TinkerPop is a graph computing framework for both graph databases (OLTP) and graph analytic systems (OLAP)."
            },
            {
              "@type": "WebSite",
              "@id": "https://tinkerpop.apache.org/#website",
              "url": "https://tinkerpop.apache.org/",
              "name": "Apache TinkerPop",
              "publisher": {
                "@id": "https://tinkerpop.apache.org/#organization"
              }
            },
            {
              "@type": "TechArticle",
              "@id": "https://tinkerpop.apache.org/gremlin.html#article",
              "headline": "Graph Query Language - Gremlin",
              "description": "Gremlin is a graph traversal language that enables developers to query graph databases with a functional, data-flow approach. Learn how to use this powerful graph query language for your data relationships.",
              "isPartOf": {
                "@id": "https://tinkerpop.apache.org/#website"
              },
              "publisher": {
                "@id": "https://tinkerpop.apache.org/#organization"
              },
              "mainEntityOfPage": {
                "@id": "https://tinkerpop.apache.org/gremlin.html#webpage"
              },
              "inLanguage": "en",
              "technicalArticle": true
            },
            {
              "@type": "WebPage",
              "@id": "https://tinkerpop.apache.org/gremlin.html#webpage",
              "url": "https://tinkerpop.apache.org/gremlin.html",
              "name": "Graph Query Language - Gremlin | Apache TinkerPop",
              "isPartOf": {
                "@id": "https://tinkerpop.apache.org/#website"
              },
              "about": {
                "@id": "https://tinkerpop.apache.org/#organization"
              },
              "description": "Gremlin is a graph traversal language that enables developers to query graph databases with a functional, data-flow approach. Learn how to use this powerful graph query language for your data relationships."
            },
            {
              "@type": "BreadcrumbList",
              "@id": "https://tinkerpop.apache.org/gremlin.html#breadcrumblist",
              "itemListElement": [
                {
                  "@type": "ListItem",
                  "position": 1,
                  "item": {
                    "@type": "WebPage",
                    "@id": "https://tinkerpop.apache.org/",
                    "url": "https://tinkerpop.apache.org/",
                    "name": "Home"
                  }
                },
                {
                  "@type": "ListItem",
                  "position": 2,
                  "item": {
                    "@type": "WebPage",
                    "@id": "https://tinkerpop.apache.org/gremlin.html",
                    "url": "https://tinkerpop.apache.org/gremlin.html",
                    "name": "Gremlin Query Language"
                  }
                }
              ]
            }
          ]
        }
        </script>
    </head>
    <body>
    <!-- header -->
    <div class="header">
        <div class="container">
            <nav class="navbar navbar-expand-lg  ">
                <div class="container-fluid">
                    <a class="navbar-brand" href="index.html">
                        <img src="img/logo.png" class="img-fluid" alt="img">
                    </a>
                    <button class="navbar-toggler" type="button" data-bs-toggle="collapse"
                            data-bs-target="#navbarSupportedContent" aria-controls="navbarSupportedContent"
                            aria-expanded="false" aria-label="Toggle navigation">
                        <span class="fa fa-bars"></span>
                    </button>
                    <div class="collapse navbar-collapse" id="navbarSupportedContent">
                        <ul class="navbar-nav ms-auto mb-2 mb-lg-0">
                            <li class="nav-item">
                                <a class="nav-link active" aria-current="page" href="index.html">Home</a>
                            </li>
                            <li class="nav-item">
                                <a class="nav-link" href="download.html">Download</a>
                            </li>

                            <li class="nav-item dropdown">
                                <a class="nav-link dropdown-toggle" href="#" id="navbarDropdown4" role="button" data-bs-toggle="dropdown" aria-expanded="false">
                                    Tools
                                </a>
                                <ul class="dropdown-menu" aria-labelledby="navbarDropdown4">
                                    <li><a class="dropdown-item" href="providers.html">Graph Systems</a></li>
                                    <li><a class="dropdown-item" href="community.html">Languages and Tools</a></li>
                                    <li><hr class="dropdown-divider"></li>
                                    <li><a class="dropdown-item" href="https://gremlify.com/">Gremlify: Try Gremlin</a></li>
                                    <li><a class="dropdown-item" href="https://tinkerpop.apache.org/gremlint">Gremlint: Lint Gremlin</a></li>
                                    <li><a class="dropdown-item" href="https://www.gremlator.com/">Gremlator: Translate Gremlin</a></li>
                                </ul>
                            </li>

                            <li class="nav-item dropdown">
                                <a class="nav-link dropdown-toggle" href="#" id="navbarDropdown" role="button"
                                   data-bs-toggle="dropdown" aria-expanded="false">
                                    Documentation
                                </a>
                                <ul class="dropdown-menu" aria-labelledby="navbarDropdown">
                                    <li class="dropdown-header">Latest Documentation</li>
                                    <li><a href="https://tinkerpop.apache.org/docs/current" class="dropdown-item">Documentation Index</a></li>
                                    <li><a href="https://tinkerpop.apache.org/docs/current/reference" class="dropdown-item">Reference</a></li>
                                    <li><a href="https://tinkerpop.apache.org/docs/current/dev/provider" class="dropdown-item">Provider</a></li>
                                    <li><a href="https://tinkerpop.apache.org/docs/current/dev/developer" class="dropdown-item">Developer</a></li>
                                    <li><a href="https://tinkerpop.apache.org/docs/current/upgrade" class="dropdown-item">Upgrade Information</a></li>
                                    <li><a href="https://tinkerpop.apache.org/javadocs/current/core/" class="dropdown-item">Core Javadoc API</a></li>
                                    <li><a href="https://tinkerpop.apache.org/javadocs/current/full/" class="dropdown-item">Full Javadoc API</a></li>
                                    <li><hr class="dropdown-divider"></li>
                                    <li><a href="https://tinkerpop.apache.org/docs/" class="dropdown-item">Documentation Archives</a></li>
                                    <li><a href="https://tinkerpop.apache.org/javadocs/" class="dropdown-item">Javadoc Archives</a></li>
                                    <li><hr class="dropdown-divider"></li>
                                    <li><a href="https://tinkerpop.apache.org/docs/current/index.html#publications" class="dropdown-item">Publications</a></li>
                                </ul>

                            </li>

                            <li class="nav-item dropdown">
                                <a class="nav-link dropdown-toggle" href="#" id="navbarDropdown1" role="button"
                                   data-bs-toggle="dropdown" aria-expanded="false">
                                    Tutorials
                                </a>
                                <ul class="dropdown-menu" aria-labelledby="navbarDropdown1">
                                    <li><a href="gremlin.html" class="dropdown-item">Introduction to Gremlin</a></li>
                                    <li><a class="dropdown-item"
                                           href="https://tinkerpop.apache.org/docs/current/tutorials/getting-started/">Getting
                                        Started</a></li>
                                    <li><a class="dropdown-item"
                                           href="https://tinkerpop.apache.org/docs/current/tutorials/the-gremlin-console/">The
                                        Gremlin Console</a></li>
                                    <li><a class="dropdown-item" href="https://tinkerpop.apache.org/docs/current/recipes/">Gremlin
                                        Recipes</a></li>
                                    <li><a class="dropdown-item"
                                           href="https://tinkerpop.apache.org/docs/current/tutorials/gremlins-anatomy/">Gremlin's
                                        Anatomy</a></li>
                                    <li>
                                        <hr class="dropdown-divider">
                                    </li>
                                    <li><a class="dropdown-item"
                                           href="http://kelvinlawrence.net/book/Gremlin-Graph-Guide.html">Book: Practical
                                        Gremlin by Kelvin Lawrence</a></li>
                                    <li><a class="dropdown-item" href="https://github.com/dkuppitz/sql2gremlin">SQL2Gremlin</a></li>
                                </ul>

                            </li>
                            <li class="nav-item dropdown">
                                <a class="nav-link dropdown-toggle" href="#" id="navbarDropdown3" role="button" data-bs-toggle="dropdown" aria-expanded="false">
                                    Community
                                </a>
                                <ul class="dropdown-menu" aria-labelledby="navbarDropdown3">
                                    <li><a class="dropdown-item" href="https://discord.gg/tinkerpop" target="_blank"><img src="img/discord-logo.png" class="nav-icon"/>Discord</a></li>
                                    <li><a class="dropdown-item" href="https://www.answeroverflow.com/c/838910279550238720"><img src="img/answer-overflow-logo.png" class="nav-icon"/>Answer Overflow</a></li>
                                    <li><a class="dropdown-item" href="https://stackoverflow.com/questions/tagged/gremlin"><img src="img/stack-overflow-logo.png" class="nav-icon"/>Stack Overflow</a></li>
                                    <li><a class="dropdown-item" href="https://groups.google.com/group/gremlin-users"><img src="img/mail.png" class="nav-icon"/>User Mailing List</a></li>
                                    <li><a class="dropdown-item" href="https://lists.apache.org/list.html?dev@tinkerpop.apache.org"><img src="img/mail.png" class="nav-icon"/>Developer Mailing List</a></li>
                                    <li><a class="dropdown-item" href="https://issues.apache.org/jira/browse/TINKERPOP/"><img src="img/jira-logo.png" class="nav-icon"/>Issue Tracker</a></li>
                                    <li><a class="dropdown-item" href="https://github.com/apache/tinkerpop/"><img src="img/github-logo.png" class="nav-icon"/>GitHub</a></li>
                                    <li><a class="dropdown-item" href="https://www.twitch.tv/apachetinkerpop"><img src="img/twitch-logo.png" class="nav-icon"/>Twitch</a></li>
                                    <li><a class="dropdown-item" href="https://twitter.com/apachetinkerpop"><img src="img/twitter-logo.png" class="nav-icon"/>Twitter</a></li>
                                    <li><a class="dropdown-item" href="https://www.youtube.com/@apachetinkerpop"><img src="img/youtube-logo.png" class="nav-icon"/>YouTube</a></li>
                                    <li><hr class="dropdown-divider"></li>
                                    <li><a  class="dropdown-item" href="https://tinkerpop.apache.org/docs/current/dev/developer/#_contributing">Contributing</a></li>
                                    <li><a  class="dropdown-item" href="https://tinkerpop.apache.org/docs/current/dev/provider/#policies">Policies</a></li>
                                </ul>
                            </li>
                            <li class="nav-item dropdown">
                                <a class="nav-link dropdown-toggle" href="#" id="navbarDropdown5" role="button"
                                   data-bs-toggle="dropdown" aria-expanded="false">
                                    Apache Software
                                </a>
                                <ul class="dropdown-menu" aria-labelledby="navbarDropdown5">
                                    <li><a class="dropdown-item" href="https://www.apache.org/">Apache Homepage</a></li>
                                    <li><a class="dropdown-item" href="https://www.apache.org/licenses/">License</a></li>
                                    <li><a class="dropdown-item"
                                           href="https://www.apache.org/events/current-event">Events</a></li>
                                    <li><a class="dropdown-item" href="https://www.apache.org/foundation/sponsorship.html">Sponsorship</a>
                                    </li>
                                    <li><a class="dropdown-item"
                                           href="https://www.apache.org/foundation/thanks.html">Thanks</a></li>
                                    <li><a class="dropdown-item" href="https://www.apache.org/security/">Security</a></li>
                                </ul>

                            </li>

                        </ul>
                    </div>
                </div>
            </nav>
        </div>
    </div>
        
        <!-- hero -->
        <div class="container hero-inner">
            <img src="img/gremlin/bg.png" class="img-fluid w-100" alt="img">
        </div>

        <!-- Content -->
        <div class="sec-pad "> 
            <div class="container">
                <div class="row d-flex justify-content-center">
                    <div class="col-md-12 col-lg-6 text-center">
                        <h1 class="ft-40 bold black mb-2">Apache TinkerPop™</h1>
                        <p class="mb-3 mb-md-5 medium black">Apache TinkerPop™ is a graph computing framework for both graph databases (OLTP) and graph analytic systems (OLAP).</p>
                    </div>
                </div>
                 <div class="row d-flex">
                    <div class="col-lg-6 mb-4 md-lg-0 text-lg-center text-start">
                        <img src="img/gremlin/about-gremlin.png" class="img-fluid " alt="img" >
                    </div>
                    <div class="col-lg-6 ">
                        <div class="use-case-page-pl-3">
                            <h2 class="ft-30 bold black mb-3 md-md-5">Gremlin Query Language</h2>
                        <p>Gremlin is the graph traversal language of Apache TinkerPop. Gremlin is a functional, data-flow language that enables users to succinctly express complex traversals on (or queries of) their application's property graph. Every Gremlin traversal is composed of a sequence of (potentially nested) steps. A step performs an atomic operation on the data stream. Every step is either a map-step (transforming the objects in the stream), a filter-step (removing objects from the stream), or a sideEffect-step (computing statistics about the stream). The Gremlin step library extends on these 3-fundamental operations to provide users a rich collection of steps that they can compose in order to ask any conceivable question they may have of their data for Gremlin is Turing Complete. </p>
                    </div>
                    </div>
                </div>
               
            </div>
        </div>
          <div class="sec-pad dark-bg"> 
            <div class="container">
                <div id="carouselExampleIndicators" class="carousel slide" data-bs-ride="carousel">
                      
                      <div class="carousel-inner">
                        <div class="carousel-item active">
                            <div class="row">
                                <div class="col-md-6 mb-4 mb-md-0">
                                    <div class="code-box h-100">
                                        <pre style="padding-left:10px;height:148px;overflow:hidden;"><code class="language-groovy">
g.V().has("name","gremlin").
  out("knows").
  out("knows").
  values("name")

                                        </code></pre>
                                    </div>
                                </div>
                                <div class="col-md-6">
                                    <p class="bold mb-2 text-white">What are the names of Gremlin's friends' friends?</p>
                                    <ul class="list-unstyled text-white op-7">
                                        <li class="mb-1">1. Get the vertex with name "gremlin."</li>
                                        <li class="mb-1">2. Traverse to the people that Gremlin knows.</li>
                                        <li class="mb-1">3. Traverse to the people those people know.</li>
                                        <li class="mb-1">4. Get those people's names.</li>
                                    </ul>
                                </div>
                            </div>
                        </div>

                        <div class="carousel-item">
                            <div class="row">
                                <div class="col-md-6 mb-4 mb-md-0">
                                    <div class="code-box h-100">
                                        <pre style="padding-left:10px;height:148px;overflow:hidden;"><code class="language-groovy">g.V().match(
  as("a").out("knows").as("b"),
  as("a").out("created").as("c"),
  as("b").out("created").as("c"),
  as("c").in("created").count().is(2)).
    select("c").by("name")</code></pre>
                                    </div>
                                </div>
                                <div class="col-md-6">
                                    <p class="bold mb-2 text-white">What are the names of the projects created by two friends?</p>
                                    <ul class="list-unstyled text-white op-7">
                                        <li class="mb-1">1. ...there exists some "a" who knows "b".</li>
                                        <li class="mb-1">2. ...there exists some "a" who created "c".</li>
                                        <li class="mb-1">3. ...there exists some "b" who created "c".</li>
                                        <li class="mb-1">4. ...there exists some "c" created by 2 people.</li>
                                        <li class="mb-1">5. Get the name of all matching "c" projects.</li>
                                    </ul>
                                </div>
                            </div>
                        </div>
                        <div class="carousel-item">
                            <div class="row">
                                <div class="col-md-6 mb-4 mb-md-0">
                                    <div class="code-box h-100">
                                        <pre style="padding-left:10px;height:148px;overflow:hidden;"><code class="language-groovy">
g.V().has("name","gremlin").
  repeat(in("manages")).
    until(has("title","ceo")).
  path().by("name")

</code></pre>
                                    </div>
                                </div>
                                <div class="col-md-6">
                                    <p class="bold mb-2 text-white">Get the managers from Gremlin to the CEO in the hierarchy.</p>
                                    <ul class="list-unstyled text-white op-7">
                                        <li class="mb-1">1. Get the vertex with the name "gremlin."</li>
                                        <li class="mb-1">2. Traverse up the management chain...</li>
                                        <li class="mb-1">3. ...until a person with the title of CEO is reached.</li>
                                        <li class="mb-1">4. ...Get name of the managers in the path traversed.</li>
                                    </ul>
                                </div>
                            </div>
                        </div>
                        <div class="carousel-item">
                            <div class="row">
                                <div class="col-md-6 mb-4 mb-md-0">
                                    <div class="code-box h-100">
                                        <pre style="padding-left:10px;height:148px;overflow:hidden;"><code class="language-groovy">
g.V().has("name","gremlin").as("a").
  out("created").in("created").
    where(neq("a")).
  groupCount().by("title")

</code></pre>
                                    </div>
                                </div>
                                <div class="col-md-6">
                                    <p class="bold mb-2 text-white">Get the distribution of titles amongst Gremlin's collaborators.</p>
                                    <ul class="list-unstyled text-white op-7">
                                        <li class="mb-1">1. Get the vertex with the name "gremlin" and label it "a."</li>
                                        <li class="mb-1">2. Get Gremlin's created projects and then who created them...</li>
                                        <li class="mb-1">3. ...that are not Gremlin.</li>
                                        <li class="mb-1">4. Group count those collaborators by their titles.</li>
                                    </ul>
                                </div>
                            </div>
                        </div>
                        <div class="carousel-item">
                            <div class="row">
                                <div class="col-md-6 mb-4 mb-md-0">
                                    <div class="code-box h-100">
                                        <pre style="padding-left:10px;height:148px;overflow:hidden;"><code class="language-groovy">g.V().has("name","gremlin").
  out("bought").aggregate("stash").
  in("bought").out("bought").
    where(not(within("stash"))).
  groupCount().order(local).by(values,desc)
</code></pre>
                                    </div>
                                </div>
                                <div class="col-md-6">
                                    <p class="bold mb-2 text-white">Get a ranked list of relevant products for Gremlin to purchase.</p>
                                    <ul class="list-unstyled text-white op-7">
                                        <li class="mb-1">1. Get the vertex with the name "gremlin."</li>
                                        <li class="mb-1">2. Get the products Gremlin has purchased and save as "stash."</li>
                                        <li class="mb-1">3. Who else bought those products and what else did they buy...</li>
                                        <li class="mb-1">4. ...that Gremlin has not already purchased.</li>
                                        <li class="mb-1">5. Group count the products and order by their relevance.</li>
                                    </ul>
                                </div>
                            </div>
                        </div>
                      </div>
                      <div class="carousel-indicators mt-5">
                        <button type="button" data-bs-target="#carouselExampleIndicators" data-bs-slide-to="0" class="active" aria-current="true" aria-label="Slide 1">1</button>
                        <button type="button" data-bs-target="#carouselExampleIndicators" data-bs-slide-to="1" aria-label="Slide 2">2</button>
                        <button type="button" data-bs-target="#carouselExampleIndicators" data-bs-slide-to="2" aria-label="Slide 3">3</button>
                        <button type="button" data-bs-target="#carouselExampleIndicators" data-bs-slide-to="3" aria-label="Slide 4">4</button>
                        <button type="button" data-bs-target="#carouselExampleIndicators" data-bs-slide-to="4" aria-label="Slide 5">5</button>
                      </div>
                    </div>
            </div>
        </div>

<div class="sec-pad "> 
            <div class="container">
                <div class="row">
                    <div class="col-12">
                         <img src="img/gremlin/oltp-and-olap.png" class="img-fluid w-100" alt="img">
                    </div>
                </div>
            </div>
        </div>
        <div class="sec-pad pt-0"> 
            <div class="container">
                <div class="row">
                     <div class="col-lg-12 ">
                            <h2 class="ft-30 bold black mb-3 md-md-5">OLTP and OLAP Traversals</h2>
                        <p>Gremlin was designed according to the "write once, run anywhere"-philosophy. This means that not only can all TinkerPop-enabled graph systems execute Gremlin traversals, but also, every Gremlin traversal can be evaluated as either a real-time database query or as a batch analytics query. The former is known as an online transactional process (OLTP) and the latter as an online analytics process (OLAP). This universality is made possible by the Gremlin traversal machine. This distributed, graph-based virtual machine understands how to coordinate the execution of a multi-machine graph traversal. Moreover, not only can the execution either be OLTP or OLAP, it is also possible for certain subsets of a traversal to execute OLTP while others via OLAP. The benefit is that the user does not need to learn both a database query language and a domain-specific BigData analytics language (e.g. Spark DSL, MapReduce, etc.). Gremlin is all that is required to build a graph-based application because the Gremlin traversal machine will handle the rest. </p>
                    </div>
                </div>
            </div>
        </div>

        <div class="sec-pad pt-0"> 
            <div class="container">
                <div class="row mb-3 mb-md-5">
                    <div class="col-md-12 col-lg-6 mb-4 mb-lg-0">
                        <div class="code-box h-100">
                                                    <code>
                                                        <span class="text-purpal">g</span><span class="text-blue">.V</span><span class="text-success">().</span><span class="text-blue">has</span><span class="text-success">("name","gremlin").</span><span class="text-blue">as</span><span class="text-success">("a").</span>

                                                            <br>&nbsp;&nbsp;<span class="text-blue">out</span><span class="text-success">("created").</span><span class="text-blue">in</span><span class="text-success">("created").</span>

                                                             <br>&nbsp;&nbsp;<span class="text-blue">where</span><span class="text-success">(</span><span class="text-blue">neq</span><span class="text-success">("a")).</span>

                                                             <br>&nbsp;&nbsp;<span class="text-blue">in</span><span class="text-success">("manages").</span>
                                                             <br>&nbsp;&nbsp;<span class="text-blue">groupCount</span><span class="text-success">().</span><span class="text-blue">by</span><span class="text-success">("name")</span>
                                                    </code>
                                                </div>
                    </div>
                    <div class="col-md-12 col-lg-6">
                        <h2 class="ft-30 bold black mb-3 md-md-5">Imperative & Declarative Traversals</h2>
                        <p>A Gremlin traversal can be written in either an imperative (procedural) manner, a declarative (descriptive) manner, or in a hybrid manner containing both imperative and declarative aspects. An imperative Gremlin traversal tells the traversers how to proceed at each step in the traversal. For instance, the imperative traversal in the first box first places a traverser at the vertex denoting Gremlin. That traverser then splits itself across all of Gremlin's collaborators that are not Gremlin himself. Next, the traversers walk to the managers of those collaborators to ultimately be grouped into a manager name count distribution. This traversal is imperative in that it tells the traversers to "go here and then go there" in an explicit, procedural manner.</p>
                    </div>
                    
                </div>

                <div class="row mb-3 mb-md-5">
                    
                    <div class="col-md-12 col-lg-6 order-2 order-md-1">
                        <p class="text-lg-end text-start">A declarative Gremlin traversal does not tell the traversers the order in which to execute their walk, but instead, allows each traverser to select a pattern to execute from a collection of (potentially nested) patterns. The declarative traversal in the second box yields the same result as the imperative traversal above. However, the declarative traversal has the added benefit that it leverages not only a compile-time query planner (like imperative traversals), but also a runtime query planner that chooses which traversal pattern to execute next based on the historic statistics of each pattern -- favoring those patterns which tend to reduce/filter the most data.</p>
                    </div>
                    <div class="col-md-12 col-lg-6 mb-4 mb-lg-0 order-1 order-md-2">
                        <div class="code-box h-100">
                                                    <code>
                                                        <span class="text-purpal">g</span><span class="text-blue">.V</span><span class="text-success">().match(</span>

                                                            <br>&nbsp;&nbsp;<span class="text-blue">as</span><span class="text-success">("a").</span><span class="text-blue">has</span><span class="text-success">("name","gremlin"),</span>

                                                            <br>&nbsp;&nbsp;<span class="text-blue">as</span><span class="text-success">("a").</span><span class="text-blue">out</span><span class="text-success">("created").as("b"),</span>

                                                            <br>&nbsp;&nbsp;<span class="text-blue">as</span><span class="text-success">("b").</span><span class="text-blue">in</span><span class="text-success">("created").as("c"),</span>

                                                            <br>&nbsp;&nbsp;<span class="text-blue">as</span><span class="text-success">("c").</span><span class="text-blue">in</span><span class="text-success">("manages").as("d"),</span>

                                                            <br>&nbsp;&nbsp;&nbsp;<span class="text-blue">where</span><span class="text-success">("a",</span><span class="text-blue">neq</span><span class="text-success">("c"))).</span>


                                                              <br>&nbsp;&nbsp;<span class="text-blue">select</span><span class="text-success">("d").</span>

                                                                <br>&nbsp;&nbsp;<span class="text-blue">groupCount</span><span class="text-success">().</span><span class="text-blue">by</span><span class="text-success">("name")</span>
                                                             
                                                    </code>
                                                </div>
                    </div>
                    
                </div>
                <div class="row">
                    <div class="col-12">
                        The user can write their traversals in any way they choose. However, ultimately when their traversal is compiled, and depending on the underlying execution engine (i.e. an OLTP graph database or an OLAP graph processor), the user's traversal is rewritten by a set of traversal strategies which do their best to determine the most optimal execution plan based on an understanding of graph data access costs as well as the underlying data systems's unique capabilities (e.g. fetch the Gremlin vertex from the graph database's "name"-index). Gremlin has been designed to give users flexibility in how they express their queries and graph system providers flexibility in how to efficiently evaluate traversals against their TinkerPop-enabled data system.
                    </div>
                </div>
            </div>
        </div>
        
         <div class="sec-pad pt-0"> 
            <div class="container">
                 <div class="row d-flex">
                    <div class="col-lg-6 mb-4 md-lg-0 text-lg-center text-start">
                        <img src="img/gremlin/language-variants.png" class="img-fluid " alt="img" >
                    </div>
                    <div class="col-lg-6 ">
                        <div class="use-case-page-pl-3">
                            <h2 class="ft-30 bold black mb-3 md-md-5">Host Language Embedding</h2>
                        <p>Classic database query languages, like SQL, were conceived as being fundamentally different from the programming languages that would ultimately use them in a production setting. For this reason, classical databases require the developer to code both in their native programming language as well as in the database's respective query language. An argument can be made that the difference between "query languages" and "programming languages" are not as great as we are taught to believe. Gremlin unifies this divide because traversals can be written in any programming language that supports function composition and nesting (which every major programming language supports). In this way, the user's Gremlin traversals are written along side their application code and benefit from the advantages afforded by the host language and its tooling (e.g. type checking, syntax highlighting, dot completion, etc.). Various Gremlin language variants exist including: Gremlin-Java, Gremlin-Groovy, Gremlin-Python, Gremlin-Scala, etc.</p>
                    </div>
                    </div>
                </div>
               <div class="row mt-3 mt-md-5">
                    <div class="col-12">
                       The first example below shows a simple Java class. Note that the Gremlin traversal is expressed in Gremlin-Java and thus, is part of the user's application code. There is no need for the developer to create a String representation of their query in (yet) another language to ultimately pass that String to the graph computing system and be returned a result set. Instead, traversals are embedded in the user's host programming language and are on equal footing with all other application code. With Gremlin, users do not have to deal with the awkwardness exemplified in the second example below which is a common anti-pattern found throughout the industry.
                    </div>
                </div>
                <div class="row mt-3 mt-md-5">
                    <div class="col-md-12 col-lg-5 mb-4 mb-lg-0">
                         <div class="code-box h-100">
                                                    <code>
                                                        <span class="text-purpal">public Class</span><span class="text-blue"> GremlinTinkerPopExample{</span>

                                                            <br>&nbsp;<span class="text-purpal">public void</span><span class="text-blue"> run(String name, String property){</span>

                                                            <br>&nbsp;&nbsp;<span class="text-blue">Graph graph</span><span class="text-success"> = </span><span class="text-blue"> GraphFactory.open(...);</span>

                                                            <br>&nbsp;&nbsp;<span class="text-blue">GraphTraversalSource</span><span class="text-purpal"> g </span><span class="text-success"> = </span><span class="text-blue">traversal().withEmbedded(graph);</span>
                                                            <br>

                                                            <br>&nbsp;&nbsp;<span class="text-blue">double avg</span><span class="text-success"> = </span><span class="text-purpal"> g</span><span class="text-success">.V().</span><span class="text-blue">has</span><span class="text-success">("name",</span><span class="text-blue">name</span><span class="text-success">).</span>

                                                            <br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="text-blue">out</span><span class="text-success">("knows").</span><span class="text-blue">out</span><span class="text-success">("created").</span>
                                                            <br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="text-blue">values(property).mean().next();</span> <br>

                                                            <br>&nbsp;&nbsp;&nbsp;<span class="text-blue">System.out.printIn</span><span class="text-success">("Average rating :" +</span><span class="text-blue">avg</span><span class="text-success">);</span>


                                                              <br>&nbsp;&nbsp;<span class="text-blue">}</span>

                                                                <br>&nbsp;<span class="text-blue">}</span>
                                                             
                                                    </code>
                                                </div>
                    </div>
                    <div class="col-md-12 col-lg-7">
                        <div class="code-box h-100">
                                                    <code>
                                                        <span class="text-purpal">public Class</span><span class="text-blue"> Sql3dbcExample {</span>

                                                            <br>&nbsp;<span class="text-purpal">public void</span><span class="text-blue"> run(String name, String property){</span>

                                                            <br>&nbsp;&nbsp;<span class="text-blue">Connection connection</span><span class="text-success"> = </span><span class="text-blue"> DriverManager.getConnection(...)</span>

                                                            <br>&nbsp;&nbsp;<span class="text-blue">Statement statement</span><span class="text-success"> = </span><span class="text-blue"> connection.createStatement();</span>

                                                            <br>&nbsp;&nbsp;<span class="text-blue">ResultSet result</span><span class="text-success"> = </span><span class="text-blue"> statement.executeQuery(</span>

                                                            <br>&nbsp;&nbsp;&nbsp;<span class="text-success">"SELECT AVG(pr."</span><span class="text-blue"> + property + </span><span class="text-success">") as AVERAGE FROM PERSONS p1" +</span>

                                                            <br>&nbsp;&nbsp;&nbsp;<span class="text-success">"INNER JOIN KNOWS K ON k. person1 pl.id +</span>
                                                            <br>&nbsp;&nbsp;&nbsp;<span class="text-success">"INNER JOIN PERSONS P2 ON p2.id k.person2 +</span>
                                                            <br>&nbsp;&nbsp;&nbsp;<span class="text-success">"INNER JOIN CREATED C ON c.person = p2.id " +</span>
                                                            <br>&nbsp;&nbsp;&nbsp;<span class="text-success">"INNER JOIN PROJECTS Pr ON pr.id c.project</span>
                                                             <br>&nbsp;&nbsp;&nbsp;<span class="text-success">"WHERE p.name "</span><span class="text-blue"> + name  + </span><span class="text-success">"');</span>

                                                            

                                                            <br>&nbsp;&nbsp;&nbsp;<span class="text-blue">System.out.println(</span><span class="text-success">"Average rating"</span><span class="text-purpal">+</span><span class="text-blue">result.next().getDouble(</span><span class="text-success">"AVERAGE"</span><span class="text-blue">));</span>


                                                              <br>&nbsp;&nbsp;<span class="text-blue">}</span>

                                                                <br>&nbsp;<span class="text-blue">}</span>
                                                             
                                                    </code>
                                                </div>
                    </div>
                </div>

                <div class="row mt-3 mt-md-5">
                    <div class="col-12">
                       Behind the scenes, a Gremlin traversal will evaluate locally against an embedded graph database, serialize itself across the network to a remote graph database, or send itself to an OLAP processor for cluster-wide distributed execution. The traversal source definition determines where the traversal executes. Once a traversal source is defined it can be used over and over again in a manner analogous to a database connection. The ultimate effect is that the user "feels" that their data and their traversals are all co-located in their application and accessible via their application's native programming language. The "query language/programming language"-divide is bridged by Gremlin.
                    </div>
                </div>
                 <div class="row mt-3 mt-md-5">
                    <div class="col-md-12 col-lg-12 ">
                         <div class="code-box h-100">
                                                    <code>
                                                        <span class="text-blue">Graph graph = GraphFactory.open(...);</span><br>
                                                        <span class="text-blue">GraphTraversalSource g;</span>

                                                            <br><span class="text-purpal">g</span><span class="text-blue"> = traversal().withEmbedded(graph); &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span class="comment-text">//local OLTP</span></span>


                                                            <br><span class="text-purpal">g</span><span class="text-blue"> =  traversal().withRemote(DriverRemoteConnection.using("<span class="text-success">Localhost</span><span class="text-blue">",</span><span class="text-purpal">8182</span><span class="text-blue">));</span> &nbsp;&nbsp;&nbsp;&nbsp; <span class="comment-text">//remote</span></span>

                                                            <br><span class="text-purpal">g</span><span class="text-blue"> =  traversal().withEmbedded(graph).withComputer(SparkGraphComputer.<span class="text-purpal">class</span><span class="text-blue">);</span> &nbsp;&nbsp;&nbsp; <span class="comment-text">//distributed OLAP</span></span>
                                                            
                                                             
                                                    </code>
                                                </div>
                    </div>
                  
                </div>
            </div>
        </div>

         <div class="sec-pad pt-0"> 
            <div class="container">
                <div class="row">
                     <div class="col-lg-12 ">
                            <h2 class="ft-30 bold black mb-3 mb-md-4">Related Resources</h2>
                    
                    </div>
                    <div class="col-md-6 col-lg-3">
                        <div class="rr-box">
                            <img src="img/gremlin/blog-01.png" class="img-fluid" alt="img">
                            <div class="rr-box-body medium text-blue">
                                <a href="#">The Benefits of the Gremlin Graph Traversal Machine</a>
                            </div>
                        </div>
                    </div>
                    <div class="col-md-6 col-lg-3">
                        <div class="rr-box">
                            <img src="img/gremlin/blog-02.png" class="img-fluid" alt="img">
                            <div class="rr-box-body medium text-blue">
                                <a href="#">The Gremlin Graph Traversal Machine and Language</a>
                            </div>
                        </div>
                    </div>
                    <div class="col-md-6 col-lg-3">
                        <div class="rr-box">
                            <img src="img/gremlin/blog-03.png" class="img-fluid" alt="img">
                            <div class="rr-box-body medium text-blue">
                                <a href="#">SQL2Gremlin Introduction</a>
                            </div>
                        </div>
                    </div>
                    <div class="col-md-6 col-lg-3">
                        <div class="rr-box">
                            <img src="img/gremlin/blog-04.png" class="img-fluid" alt="img">
                            <div class="rr-box-body medium text-blue">
                                <a href="#">How to Succeed with Apache Cassandra</a>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>

        <!-- footer -->
       
    <!-- join us -->
        <div class="join-us">
            <div class="container">
                <div class="row d-flex justify-content-center">
                    <div class="col-md-8 col-lg-6">
                        <div class="ju-box">
                            <h2 class="ft-40 text-blue bold">Join Us</h2>
                            <p class="bold">Join us on our Discord Server</p>
                            <a href="https://discord.gg/tinkerpop"><img src="img/tpvewx.png" class="img-fluid mt-3" alt="img"></a>
                        </div>
                    </div>
                </div>
            </div>
        </div>
        
        <!-- footer -->
        <footer>
            <div class="primary-footer sec-pad">
                <div class="container">
                    <div class="row">
                        <div class="col-md-4">
                            <div class="bold ft-25">Apache TinkerPop™</div>
                            <p class="mt-2 mb-4">Apache TinkerPop™ is a graph computing framework for both graph databases (OLTP) and graph analytic systems (OLAP).</p>
                            <ul class="list-unstyled list-inline hover-op-low">
                                <li class="list-inline-item"><a href="https://discord.gg/tinkerpop"><img src="img/social/discord.svg" class="img-fluid" alt="img"></a></li>
                                <li class="list-inline-item"><a href="https://github.com/apache/tinkerpop"><img src="img/social/github-box.svg" class="img-fluid" alt="img"></a></li>
                                <li class="list-inline-item"><a href="https://www.twitch.tv/apachetinkerpop"><img src="img/social/twitch.png" class="img-fluid" alt="img"></a></li>
                                <li class="list-inline-item"><a href="https://twitter.com/apachetinkerpop"><img src="img/social/twitter-square.svg" class="img-fluid" alt="img"></a></li>
                                <li class="list-inline-item"><a href="https://www.youtube.com/@apachetinkerpop"><img src="img/social/youtube.png" class="img-fluid" alt="img"></a></li>
                            </ul>
                        </div>
                        <div class="col-md-4 ft-links">
                            <div class="bold ft-18 mb-3">Links</div>
                            <div class="row">
                                <div class="col-lg-6">
                                    <ul class="hover-op-low list-unstyled">
                                        <li><a href="index.html">Home</a></li>
                                        <li><a href="download.html">Downloads</a></li>
                                        <li><a href="https://tinkerpop.apache.org/docs/current">Documentation</a></li>
                                        <li><a href="https://privacy.apache.org/policies/privacy-policy-public.html" target="_blank">Privacy Policy</a></li>
                                    </ul>
                                </div>
                                <div class="col-lg-6">
                                     <ul class="hover-op-low list-unstyled">
                                        <li><a href="https://tinkerpop.apache.org/docs/current/dev/developer#_contributing">Contributing</a></li>
                                        <li><a href="providers.html">Providers</a></li>
                                        <li><a href="community.html">Community</a></li>
                                    </ul>
                                </div>
                            </div>
                        </div>
                        <div class="col-md-4 mt-4">
                            <p>Apache TinkerPop, TinkerPop, Apache, Apache feather logo, and Apache TinkerPop project logo are either registered trademarks or trademarks of The Apache Software Foundation in the United States and other countries.</p>
                        </div>
                    </div>
                </div>
            </div>
            <div class="secondry-footer">
                <div class="container">
                    <div class="row">
                        <div class="col-12">
                            Copyright © 2015-2025 The Apache Software Foundation
                        </div>
                    </div>
                </div>
            </div>
        </footer>
        <script src="js/jquery-1.12.4.min.js"></script>
        <script src="js/bootstrap.bundle.min.js"></script>
        <script src="js/wow.min.js"></script>
        <script src="js/my.js"></script>
        <script src="js/prism.js"></script>
    </body>
</html>
